


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class LC_107 {
    public List<List<Integer>> levelOrderBottom(LC_144.TreeNode root) {
        List<List<Integer>> lists = new ArrayList<>();
        Queue<LC_144.TreeNode> que = new LinkedList<>();
        int size = 1;
        if(root == null){
            return lists;
        }
        que.offer(root);
        while(!que.isEmpty()){
            List<Integer> list = new ArrayList<>();
            int len = size;
            size = 0;
            while(len != 0){
                len--;
                LC_144.TreeNode node = que.poll();
                list.add(node.val);
                if(node.left != null){
                    size++;
                    que.offer(node.left);
                }
                if(node.right != null){
                    size++;
                    que.offer(node.right);
                }
            }
            lists.add(0, list);
        }
        return lists;
    }
}
